home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / LOCALM~1 / Math.bas < prev    next >
BASIC Source File  |  1997-06-14  |  3KB  |  135 lines

  1. Attribute VB_Name = "MMath"
  2. Option Explicit
  3.  
  4. Public Enum EErrorMath
  5.     eeBaseMath = 13520      ' Math
  6. End Enum
  7.  
  8. ' Derived math functions from language reference Appendix D
  9.  
  10. ' Secant
  11. Function Sec(x As Double) As Double
  12.     Sec = 1 / Cos(x)
  13. End Function
  14.  
  15. ' Cosecant
  16. Function CoSec(x As Double) As Double
  17.     CoSec = 1 / Sin(x)
  18. End Function
  19.  
  20. ' Cotangent
  21. Function CoTan(x As Double) As Double
  22.     CoTan = 1 / Tan(x)
  23. End Function
  24.  
  25. ' Inverse Sine
  26. Function ArcSin(x As Double) As Double
  27.     ArcSin = Atn(x / Sqr(-x * x + 1))
  28. End Function
  29.  
  30. ' Inverse Cosine
  31. Function ArcCos(x As Double) As Double
  32.     ArcCos = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1)
  33. End Function
  34.  
  35. ' Inverse Secant
  36. Function ArcSec(x As Double) As Double
  37.     ArcSec = Atn(x / Sqr(x * x - 1)) + Sgn(x - 1) * (2 * Atn(1))
  38. End Function
  39.  
  40. ' Inverse Cosecant
  41. Function ArcCoSec(x As Double) As Double
  42.     ArcCoSec = Atn(x / Sqr(x * x - 1)) + (Sgn(x) - 1) * (2 * Atn(1))
  43. End Function
  44.  
  45. ' Inverse Cotangent
  46. Function ArcCoTan(x As Double) As Double
  47.     ArcCoTan = Atn(x) + 2 * Atn(1)
  48. End Function
  49.  
  50. ' Hyperbolic Sine
  51. Function HSin(x As Double) As Double
  52.     HSin = (Exp(x) - Exp(-x)) / 2
  53. End Function
  54.  
  55. ' Hyperbolic Cosine
  56. Function HCos(x As Double) As Double
  57.     HCos = (Exp(x) + Exp(-x)) / 2
  58. End Function
  59.  
  60. ' Hyperbolic Tangent
  61. Function HTan(x As Double) As Double
  62.     HTan = (Exp(x) - Exp(-x)) / (Exp(x) + Exp(-x))
  63. End Function
  64.  
  65. ' Hyperbolic Secant
  66. Function HSec(x As Double) As Double
  67.     HSec = 2 / (Exp(x) + Exp(-x))
  68. End Function
  69.  
  70. ' Hyperbolic Cosecant
  71. Function HCoSec(x As Double) As Double
  72.     HCoSec = 2 / (Exp(x) - Exp(-x))
  73. End Function
  74.  
  75. ' Hyperbolic Cotangent
  76. Function HCotan(x As Double) As Double
  77.     HCotan = (Exp(x) + Exp(-x)) / (Exp(x) - Exp(-x))
  78. End Function
  79.  
  80. ' Inverse Hyperbolic Sine
  81. Function HArcSin(x As Double) As Double
  82.     HArcSin = Log(x + Sqr(x * x + 1))
  83. End Function
  84.  
  85. ' Inverse Hyperbolic Cosine
  86. Function HArcCos(x As Double) As Double
  87.     HArcCos = Log(x + Sqr(x * x - 1))
  88. End Function
  89.  
  90. ' Inverse Hyperbolic Tangent
  91. Function HArcTan(x As Double) As Double
  92.     HArcTan = Log((1 + x) / (1 - x)) / 2
  93. End Function
  94.  
  95. ' Inverse Hyperbolic Secant
  96. Function HArcSec(x As Double) As Double
  97.     HArcSec = Log((Sqr(-x * x + 1) + 1) / x)
  98. End Function
  99.  
  100. ' Inverse Hyperbolic Cosecant
  101. Function HArcCoSec(x As Double) As Double
  102.     HArcCoSec = Log((Sgn(x) * Sqr(x * x + 1) + 1) / x)
  103. End Function
  104.  
  105. ' Inverse Hyperbolic Cotangent
  106. Function HArcCoTan(x As Double) As Double
  107.     HArcCoTan = Log((x + 1) / (x - 1)) / 2
  108. End Function
  109.  
  110. ' Logarithm to base N
  111. Function LogN(x As Double, n As Double) As Double
  112.     LogN = Log(x) / Log(n)
  113. End Function
  114.  
  115. #If fComponent = 0 Then
  116. Private Sub ErrRaise(e As Long)
  117.     Dim sText As String, sSource As String
  118.     If e > 1000 Then
  119.         sSource = App.ExeName & ".Math"
  120.         Select Case e
  121.         Case eeBaseMath
  122.             BugAssert True
  123.        ' Case ee...
  124.        '     Add additional errors
  125.         End Select
  126.         Err.Raise COMError(e), sSource, sText
  127.     Else
  128.         ' Raise standard Visual Basic error
  129.         sSource = App.ExeName & ".VBError"
  130.         Err.Raise e, sSource
  131.     End If
  132. End Sub
  133. #End If
  134.  
  135.